<!-- 用户档案页 -->
<template>
  <!-- 面包屑 -->
  <div style="margin: 20px;">
    <el-breadcrumb separator="/" style="line-height:35px">
      <el-breadcrumb-item><span style="color: #7A7A7A;">服务管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #7A7A7A;">用户管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #0468FF;font-weight: bold">用户档案</span></el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <!-- 搜索卡片 -->
  <el-card style="margin: 20px;height: 120px;border: 0" shadow="never">
    <el-form>
      <el-row :gutter="30">
        <el-col :span="8">
          <el-form-item label="老人姓名">
            <el-input placeholder="请输入老人姓名" v-model="searchForm.patientName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="证件号码">
            <el-input placeholder="请输入老人证件号" v-model="searchForm.idNumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="亲属电话">
            <el-input placeholder="请输入亲属电话" v-model="searchForm.familyPhone"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="8">
          <el-form-item label="建档时间">
            <el-date-picker
                type="date"
                placeholder="请选择日期"
                value-format="YYYY-MM-DD HH:mm:ss"
                format="YYYY-MM-DD"
                v-model="searchForm.checkInTime"
                style="width: 300px;"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8"></el-col>
        <el-col :span="5">
          <el-form-item>
            <el-button @click="resetSearch">重置</el-button>
            <el-button type="primary" @click="">查询</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-button type="primary" style="margin-left: 24px;" @click="addArchivesView">新建档案</el-button>
        </el-col>
      </el-row>
    </el-form>
  </el-card>

  <!-- 列表 -->
  <el-card style="margin:20px;border: 0" shadow="never">
    <el-table :data="currentTableData" height="550px"
              :row-style="{'height':'50px'}"
              :cell-style="{'color':'#000'}"
              :header-cell-style="{
                'background-color': '#f2f2f2',
                'color': '#000',
                'height':'50px'
              }">
      <el-table-column prop="id" label="档案编码" align="center"/>
      <el-table-column prop="patientName" label="老人姓名" align="center"/>
      <el-table-column prop="gender" label="性别" align="center"/>
      <el-table-column prop="age" label="年龄" align="center"/>
      <el-table-column prop="idNumber" label="证件号" align="center" width="200"/>
      <el-table-column prop="checkInTime" label="建档时间" align="center" width="250"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" @click="editArchives(scope.row.id)">编辑</el-button>
          <el-button link type="danger" @click="deleteArchives(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
        style="margin-top: 20px;margin-left: 5px;"
    />
  </el-card>

</template>

<script setup>
//搜索栏数据
import {onMounted, ref} from "vue";

const searchForm = ref({patientName: '', idNumber: '', familyPhone: '', checkInTime: ''});
//重置搜索栏
const resetSearch = () => {
  searchForm.value = {patientName: '', idNumber: '', familyPhone: '', checkInTime: ''}
  loadPatient()
}
//表格数据
const tableData = ref([]);
const currentTableData = ref([]) // 当前页显示的数据
const currentPage = ref(1)      // 当前页码
const pageSize = ref(10)        // 每页条数

//加载表格数据
const loadPatient = () => {
  tableData.value = []
  for (let i = 0; i < 15; i++) {
    tableData.value.push({
      id: 'JK20180606001',
      patientName: '刘姥姥',
      gender: '女',
      age: '69',
      idNumber: '6130************68',
      checkInTime: '2018-06-06 09:01:50'
    })
  }
}
onMounted(() => {
  loadPatient()
})

// 获取数据（示例）
const fetchData = async () => {
  // 这里替换为你的API请求
  // dataTable.value = await api.getData();
  updateCurrentData();
}

// 更新当前页数据
const updateCurrentData = () => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  currentTableData.value = tableData.value.slice(start, end)
}

// 每页条数变化
const handleSizeChange = (val) => {
  pageSize.value = val
  updateCurrentData()
}

// 页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val
  updateCurrentData()
}

// 生命周期钩子
onMounted(() => {
  fetchData()
})


//新增
const addArchivesView = () => {

}
//编辑
const editArchives = (id) => {

}
//删除
const deleteArchives = (id) => {

}
</script>

<style scoped>

</style>